/*
 * MIT License
 *
 * Copyright (c) 2020 wen.gu <454727014@qq.com>
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

/***************************************************************************
 * Name: scale_linear.h
 *
 * Purpose: The following section describes the ScaleLinearAndTexttable class template
 *          used in ara::com. The objects of this class at a given time either hold the value of
 *          an enumerator of a specific enum class or other values of the underlying type of this.
 *          The used enum class is specified through a template argument
 *
 * Developer:
 *   wen.gu , 2020-04-21
 *
 * TODO:
 *
 ***************************************************************************/

#ifndef __ARA_COM_SCALE_LINEAR_H__
#define __ARA_COM_SCALE_LINEAR_H__
/******************************************************************************
 **    INCLUDES
 ******************************************************************************/

#include <type_traits>
/******************************************************************************
 **    MACROS
 ******************************************************************************/


/******************************************************************************
 **    TYPE DEFINITIONS
 ******************************************************************************/
namespace ara
{
namespace com
{

/******************************************************************************
 **    CLASSES/FUNCTIONS DEFINITIONS
 ******************************************************************************/

template <typename T>
class ScaleLinearAndTexttable
{
public:
    // Declaration of the underlying_type
    static_assert(std::is_enum<T>::value, "Type T has to be an enum");
    using underlying_type = typename std::underlying_type<T>::type;
public:
    // Default constructor
    explicit ScaleLinearAndTexttable()
        :mVal(underlying_type())
    {
        /** todo something */
    }
    // Copy constructor
    explicit ScaleLinearAndTexttable(const ScaleLinearAndTexttable& v)
        :mVal(v.mVal)
    {
        /** todo something */
    }
    // Constructing an object from an enum
    explicit ScaleLinearAndTexttable(const T& v)
        :mVal(static_cast<underlying_type>(v))
    {
        /** todo something */
    }
    // Constructing an object from the underlying type of an enum
    explicit ScaleLinearAndTexttable(const underlying_type& v)
        :mVal(v)
    {
        /** todo something */
    }

public:
    // Copy assignment operator
    ScaleLinearAndTexttable& operator=(const ScaleLinearAndTexttable& v)
    {
        mVal = v.mVal;
    }

    // Assignment operator from an enum
    ScaleLinearAndTexttable& operator=(const T& v)
    {
        mVal = static_cast<underlying_type>(v);
    }
    // Assignment operator from the underlying type of an enum
    ScaleLinearAndTexttable& operator=(const underlying_type& v)
    {
        mVal = v;
    }
    // Casting operator to the underlying_type
    explicit operator underlying_type() const
    {
        return mVal;
    }

public:
    // Equal to operator to another ScaleLinearAndTexttable<T>
    friend bool operator==(const ScaleLinearAndTexttable<T>& lhs, const ScaleLinearAndTexttable<T>& rhs);
    // Equal to operator to the underlying_type
    friend bool operator==(const ScaleLinearAndTexttable<T>& lhs, const underlying_type& rhs);
    // Equal to operator to the underlying_type
    friend bool operator==(const underlying_type& lhs, const ScaleLinearAndTexttable<T>& rhs);
    // Equal to operator to the enum
    friend bool operator==(const ScaleLinearAndTexttable<T>& lhs, const T& rhs);
    // Equal to operator to the enum
    friend bool operator==(const T& lhs, const ScaleLinearAndTexttable<T>& rhs);
    // Not-equal to operator to another ScaleLinearAndTexttable<T>
    friend bool operator!=(const ScaleLinearAndTexttable<T>& lhs, const ScaleLinearAndTexttable<T>& rhs);
    // Not-equal to operator to the underlying_type
    friend bool operator!=(const ScaleLinearAndTexttable<T>& lhs, const underlying_type& rhs);
    // Not-equal to operator to the underlying_type
    friend bool operator!=(const underlying_type& lhs, const ScaleLinearAndTexttable<T>& rhs);
    // Not-equal to operator to the enum
    friend bool operator!=(const ScaleLinearAndTexttable<T>& lhs, const T& rhs);
    // Not-equal to operator to the enum
    friend bool operator!=(const T& lhs, const ScaleLinearAndTexttable<T>& rhs);

private:
    underlying_type mVal;
};

///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////

// Equal to operator to another ScaleLinearAndTexttable<T>
template <typename T>
bool operator==(const ScaleLinearAndTexttable<T>& lhs, const ScaleLinearAndTexttable<T>& rhs)
{
    return lhs.mVal == rhs.mVal;
}

// Equal to operator to the underlying_type
template <typename T>
bool operator==(const ScaleLinearAndTexttable<T>& lhs, const typename std::underlying_type<T>::type& rhs)
{
    return lhs.mVal == rhs;
}

// Equal to operator to the underlying_type
template <typename T>
bool operator==(const typename std::underlying_type<T>::type& lhs, const ScaleLinearAndTexttable<T>& rhs)
{
    return lhs == rhs.mVal;
}

// Equal to operator to the enum
template <typename T>
bool operator==(const ScaleLinearAndTexttable<T>& lhs, const T& rhs)
{
    return lhs.mVal == static_cast<typename std::underlying_type<T>::type>(rhs);
}

// Equal to operator to the enum
template <typename T>
bool operator==(const T& lhs, const ScaleLinearAndTexttable<T>& rhs)
{
    return static_cast<typename std::underlying_type<T>::type>(lhs) == rhs.mVal;
}

// Not-equal to operator to another ScaleLinearAndTexttable<T>
template <typename T>
bool operator!=(const ScaleLinearAndTexttable<T>& lhs, const ScaleLinearAndTexttable<T>& rhs)
{
    return lhs.mVal != rhs.mVal;
}

// Not-equal to operator to the underlying_type
template <typename T>
bool operator!=(const ScaleLinearAndTexttable<T>& lhs, const typename std::underlying_type<T>::type& rhs)
{
    return lhs.mVal != rhs;
}

// Not-equal to operator to the underlying_type
template <typename T>
bool operator!=(const typename std::underlying_type<T>::type& lhs, const ScaleLinearAndTexttable<T>& rhs)
{
    return !lhs != rhs.mVal;
}

// Not-equal to operator to the enum
template <typename T>
bool operator!=(const ScaleLinearAndTexttable<T>& lhs, const T& rhs)
{
    return  lhs.mVal != static_cast<typename std::underlying_type<T>::type>(rhs);
}

// Not-equal to operator to the enum
template <typename T>
bool operator!=(const T& lhs, const ScaleLinearAndTexttable<T>& rhs)
{
    return static_cast<typename std::underlying_type<T>::type>(lhs) != rhs.mVal;
}



} /** namespace com */
} /** namespace ara */

#endif /** !__ARA_COM_SCALE_LINEAR_H__ */

